package com.isoft.demo.service.impl;

import com.isoft.demo.common.ResponseData;
import com.isoft.demo.dao.FilialDao;
import com.isoft.demo.entity.Emp;
import com.isoft.demo.entity.Filial;
import com.isoft.demo.service.FilialService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class FilialServiceImpl implements FilialService {
    @Resource
    private FilialDao dao;

    @Override
    public ResponseData addFil(Filial filial) {
        int n = dao.addFilial(filial);
        ResponseData rs = new ResponseData();
        List list = new ArrayList();
        if(n > 0){
            rs.setCode(0);
            rs.setMsg("添加成功");
            list.add(filial);
            rs.setData(list);
        } else{
            rs.setCode(1);
            rs.setMsg("添加失败");
        }
        return rs;
    }

//    @Override
//    public ResponseData deleteFil(int fid) {
//        int a = dao.deleteFilial(fid);
//        ResponseData rs = new ResponseData();
//        if(a != 0){
//            rs.setCode(0);
//            rs.setMsg("删除成功！");
//        } else{
//            rs.setCode(1);
//            rs.setMsg("删除失败!");
//        }
//        return rs;
//    }

    @Override
    public ResponseData updateFil(Filial filial) {
        int m = dao.updateFilial(filial);
        ResponseData rs = new ResponseData();
        if(m != 0){
            rs.setCode(0);
            rs.setMsg("修改成功！");
        } else{
            rs.setCode(1);
            rs.setMsg("修改失败!");
        }
        return rs;
    }

    @Override
    public ResponseData searchAll() {
        List<Filial> list = dao.searchAll();
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        }else {
            rs.setCode(1);
            rs.setMsg("fail");
        }
        return rs;
    }

    @Override
    public ResponseData findByFid(Integer fid) {
        List<Filial>list = dao.findByFid(fid);
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        }else {
            rs.setCode(1);
            rs.setMsg("fail");
        }
        return rs;
    }
}
